package io.huaguoguo.redis;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 描述：  <br>
 * CreateDate: 2021/5/18 <br>
 *
 * @author huaguoguo
 */
public class LRUCache extends LinkedHashMap<Integer, Integer> {

    private int capacity;

    public LRUCache(int capacity) {
        super(capacity, 0.75F, true);
        this.capacity = capacity;

    }

    public int get(int key) {
        return super.getOrDefault(key,-1);
    }

    public void put(int key, int value) {
        super.put(key,value);
    }

    @Override
    protected boolean removeEldestEntry(Map.Entry<Integer, Integer> eldest) {
        return size() > capacity;
    }

    public static void main(String[] args) {
        LRUCache lruCache = new LRUCache(8);
        lruCache.put(12,23);
        lruCache.put(13,54);
        lruCache.put(14,75);
        lruCache.put(15,98);
        int value = lruCache.get(14);
        System.out.println(value);
    }
}
